第一步:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
在onCreate裡面新增以下code
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
web_view.loadUrl("file:///android_asset/error.html");
}
第二步:
建立一個error.xml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Error</title>
</head>
<body style=" background:#CCC">
<div style="margin:0 auto;">
<span>
<h1 align="center" id="title" style="font-family:微軟正黑體;">歐歐,出错了……</h1>
</span>
<span>
<h3 align="center"><a href="http://192.168.1.82/amily/">回首頁</a></h3>
</span>
</div>
</body>
</html>
第三步:
建立assets資料夾並將error.html放入assets資料夾中
方法:app>src>main>右鍵New>Folder>Asset Folder